package com.example.iread.util;

import android.graphics.Color;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public final class WindowUtil {

    /**
     * 沉浸式状态栏
     * @param window getWindow()
     */
    public static void setTransparentStatusBar(Window window) {
        window.clearFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | // 半透明StatusBar,并且不会因用户交互而被清除。
                        WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION // 半透明NavigationBar,并且不会因用户交互而被清除。
        );
        window.addFlags(
                WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
        );
        window.setStatusBarColor(Color.TRANSPARENT);
        window.getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        );
        window.setNavigationBarColor(Color.TRANSPARENT);
    }

}
